package agent.variables;
import org.snmp4j.agent.MOAccess;
import org.snmp4j.agent.mo.MOScalar;
import org.snmp4j.agent.mo.MOValueValidationEvent;
import org.snmp4j.agent.mo.MOValueValidationListener;
import org.snmp4j.agent.request.SubRequest;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;

import agent.monitors.TorrentMonitorImpl;

public class MaxActive extends MOScalar<OctetString> {
	/**
	 * The <code>MaxActiveValidator</code> implements the value validation for <code>MaxActive</code>.
	 */
	static class MaxActiveValidator implements MOValueValidationListener {
		public void validate(MOValueValidationEvent validationEvent) {
		}
	}
	
	public MaxActive(OID oid, MOAccess access) {
		super(oid, access, new OctetString());
		this.addMOValueValidationListener(new MaxActiveValidator());
	}
	
	@SuppressWarnings("rawtypes")
	public int isValueOK(SubRequest request) {
		int valueOK = super.isValueOK(request);
		if (valueOK != SnmpConstants.SNMP_ERROR_SUCCESS) {
			return valueOK;
		}
		return valueOK;
	}
	
	public OctetString getValue() {
		return new OctetString(TorrentMonitorImpl.getInstance().getMonitor().getMaxActive());
	}
	
	public int setValue(OctetString newValue) {
		TorrentMonitorImpl.getInstance().getMonitor().setMaxActive(newValue);
		return 0;
	}
}